package top.zhangjianyong.tools;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author ： zhangjianyong
 * @date ： 2024/4/13 11:04
 */
public class NSDownload {

    public static void download() {
        int offset = 0;
        int limit = 20;
        int size = limit;

        JSONArray array = new JSONArray();
        ExcelWriter writer = ExcelUtil.getWriter("本地/ns.xlsx", "1");

        while (size == limit) {
            String url = "https://switch.jumpvg.com/jump/findGame/list?categoryList=&featureList=&limit=" + limit
                    + "&offset=" + offset + "&platForm=1&session=1671087119935&subPlatform=1&systemList=&type=5&version=3";

            HttpRequest get = HttpUtil.createGet(url);
            try {
                String body = get.execute().body();
                JSONObject json = JSONObject.parseObject(body);
                JSONArray data = json.getJSONArray("data");
                array.addAll(data);
                size = data.size();
                offset = offset + limit;
            }catch (Exception e){
                continue;
            }
            System.out.println(offset);
        }

        writer.write(array).flush().close();
        System.out.println(array.size());

    }

    public static void main(String[] args) {
        download();
    }
}
